local xuanwei = fk.CreateSkill{
  name = "ls__xuanwei",
}

Fk:loadTranslationTable{
  ["ls__xuanwei"] = "悬威",
  ["@@ls__xuanwei"] = "悬威",
  [":ls__xuanwei"] = "出牌阶段开始时或当你造成伤害后，你可选择一名攻击范围内的角色，其下次使用【杀】造成伤害后，若对方体力值小于/不小于其，则其失去1点体力/弃置一张牌。",
  ["#ls__xuanwei-target"] = "悬威：你可选择一名其他角色",
  --["#ls__xuanwei-discard"] = "擢目：你可弃置%arg张牌并回复1点体力",

  ["$ls__xuanwei1"] = "我眼睛里可容不得沙子！",
  ["$ls__xuanwei2"] = "能法之事，必强易而尽职。",
}

local spec = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xuanwei.name) and (event == fk.Damage or player.phase == Player.Play)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = table.filter(room:getOtherPlayers(player), function (p) return player:inMyAttackRange(p) end),
      skill_name = "ls__xuanwei",
      prompt = "#ls__xuanwei-target",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    player.room:addPlayerMark(to, "@@ls__xuanwei")
  end,
}

xuanwei:addEffect(fk.Damage, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xuanwei.name, true, true) and target ~= player and target:getMark("@@ls__xuanwei") > 0
    and data.to:isAlive() and data.card and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "@@ls__xuanwei", 0)
    if target.hp > data.to.hp then
      room:loseHp(target, 1, xuanwei.name)
    elseif not target:isNude() then
      room:askToDiscard(target, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = xuanwei.name,
        cancelable = false,
      })
    end
  end,
})

xuanwei:addEffect(fk.EventPhaseStart, spec)
xuanwei:addEffect(fk.Damage, spec)

return xuanwei